<?php

namespace app\admin\model;

use think\Model;

class DormitoryDormBed extends Model
{
    // 连接数据库名称
    //protected $connection = 'db2';
    // 表名
    protected $name = 'dormitory_dorm_bed';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = false;

    //protected $append = ['status_text'];

    const XIANZHI = 1;
    const ZAIYONG = 2;

    public static $statusList = [
        '1' => '闲置',
        '2' => '在用',
    ];

    public function creator()
    {
        return $this->belongsTo('Admin', 'creator_id', 'id', [], 'LEFT')->field('id,nickname');
    }

    public function student()
    {
        return $this->belongsTo('Student', 'student_id', 'id', [], 'LEFT')->field('id,name');
    }

    public function faculty()
    {
        return $this->belongsTo('Faculty', 'faculty_id', 'id', [], 'LEFT')->field('id,name');
    }

    public function getStatusTextAttr($value, $data)
    {
        return isset(static::$statusList[$data['status']]) ? static::$statusList[$data['status']] : '';
    }

}
